package com.hh.test.sort;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class GameSort {

	public static void main(String[] args) {
		InputStreamReader input = new InputStreamReader(System.in);
		BufferedReader read = new BufferedReader(input);
		try {
			String str = read.readLine();
			if (str.length() != 4) {
				System.out.println("输入4位数");
				str = read.readLine();
			}
			new GameSort().swap(str);
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

	void swap(String str) {
		String[] ins = str.split("");
		Integer[] array = new Integer[4];
		for (int j = 0; j < ins.length; j++) {
			array[j] = Integer.valueOf(ins[j]);
		}

		new RadixSort().sort(array);
		Integer max = arrayToInt(array, true);
		Integer min = arrayToInt(array, false);
		System.out.print("max:" + max + " - ");
		System.out.print("min:" + min + " ");
		System.out.println(" = " + (max - min));
		if (max - min != 6174) {
			// if (max - min != 8532) {
			swap((max - min) + "");
		}
	}

	static Integer arrayToInt(Integer[] array, boolean f) {
		String a = "";
		for (int j = 0; j < array.length; j++) {
			if (f) {
				a = array[j] + a;
			} else {
				a += array[j];
			}
		}
		return Integer.valueOf(a);
	}

}
